home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / BM192A.ZIP / TIMING.S < prev    next >
Encoding:
Text File  |  1996-02-23  |  7.4 KB  |  363 lines

  1. *=======================================================*
  2. *    Timing module: latest update 23/02/96        *
  3. *=======================================================*
  4. *    Interrupts for timing & synchronisation        *
  5. *=======================================================*
  6.  
  7. timerc        =    $114
  8.  
  9. cdcr        =    $fffffa1d
  10. tcdr        =    $fffffa23
  11.  
  12. frames_per_sec
  13.  
  14. *-------------------------------------------------------*
  15. init_timing:
  16. *-------------------------------------------------------*
  17.     push.w        sr
  18.     move.w        #$2700,sr
  19.     ifd        debuggable
  20.     move.l        $4d2.w,old_vbi
  21.     move.l        #new_vbi,$4d2.w
  22.     elseif
  23.     move.l        $70.w,old_vbi
  24.     move.l        #new_vbi,$70.w
  25.     endc
  26.     ifd        enable_timing
  27.     move.l        timerc.w,old_timerc
  28.     move.l        #framecounter,timerc.w
  29.     and.b        #%00001111,cdcr.w
  30.     move.b        #192,tcdr.w        ; 2457600/192 = 12800Hz
  31.     or.b        #(5<<4),cdcr.w        ; 12800/64 = 200Hz
  32.     endc
  33.     pop.w        sr
  34.     ifd        enable_timing
  35.     bsr        init_font
  36.     endc
  37.     rts
  38.  
  39. *-------------------------------------------------------*
  40. reset_timing:
  41. *-------------------------------------------------------*
  42.     push.w        sr
  43.     move.w        #$2700,sr
  44.     ifd        enable_timing
  45.     move.l        old_timerc,timerc.w
  46.     endc
  47.     ifd        debuggable
  48.     move.l        old_vbi,$4d2.w
  49.     elseif
  50.     move.l        old_vbi,$70.w
  51.     endc
  52.     pop.w        sr
  53.     rts
  54.  
  55. *-------------------------------------------------------*
  56.     txtlong
  57. *-------------------------------------------------------*
  58. timing:
  59. *-------------------------------------------------------*
  60.     ifd        enable_timing
  61.     move.w        #8,char_x
  62.     move.w        #8,char_y
  63.     move.w        #$FFFF,char_col
  64.     lea        stringspace,a0
  65.     clr.b        (a0)
  66.     move.l        a0,numtext_ptr
  67.     ifd        frames_per_sec
  68.     lea        fps,a0
  69.     bsr        pushtext
  70.     bsr        average_times
  71.     move.l        #200*8,d0
  72.     swap        d0
  73.     divu.l        d1,d0
  74.     push.l        d0
  75.     mulu.w        #10000,d0
  76.     swap        d0
  77.     ext.l        d0
  78.     moveq        #4,d7
  79.     bsr        pushdigits
  80.     lea        point,a0
  81.     bsr        pushtext
  82.     pop.l        d0
  83.     swap        d0
  84.     ext.l        d0
  85.     moveq        #1,d7
  86.     bsr        pushdigits
  87.     elseif
  88.     lea        frames,a0
  89.     bsr        pushtext
  90.     bsr        average_times
  91.     move.l        d1,d0
  92.     moveq        #1,d7
  93.     bsr        pushdigits
  94.     endc
  95.     move.l        numtext_ptr,a0
  96.     jsr        print_line
  97.     endc
  98.     rts
  99.  
  100. *-------------------------------------------------------*
  101.     txtlong
  102. *-------------------------------------------------------*
  103. average_times:
  104. *-------------------------------------------------------*
  105.     ifd        frames_per_sec
  106.     lea        fc_history,a0
  107.     moveq        #8-2,d0
  108.     move.l        fpsc,d1
  109.     clr.l        fpsc
  110.     move.l        d1,d3
  111. .lp:    move.l        4(a0),d2
  112.     add.l        d2,d1
  113.     move.l        d2,(a0)+
  114.     dbra        d0,.lp
  115.     move.l        d3,(a0)
  116.     add.l        fpso,d1
  117.     lsr.l        d1
  118.     move.l        d1,fpso
  119.     elseif
  120.     move.l        ovbls,d1
  121.     add.l        vbls,d1
  122.     clr.l        vbls
  123.     lsr.l        d1
  124.     move.l        d1,ovbls
  125.     endc
  126.     rts
  127.     
  128. *-------------------------------------------------------*
  129.     txtlong
  130. *-------------------------------------------------------*
  131. pushdigits:
  132. *-------------------------------------------------------*
  133. ;    d0     =     number
  134.     move.l        numtext_ptr,a0
  135.     move.l        a0,a1
  136.     moveq        #'0',d3
  137.     move.l        d3,d1
  138.     moveq        #10,d4
  139.     tst.l        d0
  140.     beq.s        .zero
  141. .loop    ext.l        d0
  142.     divu        d4,d0
  143.     move.l        d0,d1
  144.     swap        d1
  145.     add.w        d3,d1
  146. .zero:    move.b        d1,-(a0)
  147.     subq.l        #1,d7
  148.     bgt.s        .loop
  149.     tst.w        d0
  150.     bne.s        .loop
  151.     move.l        a0,numtext_ptr
  152.     rts
  153.  
  154. *-------------------------------------------------------*
  155.     txtlong
  156. *-------------------------------------------------------*
  157. pushtext:
  158. *-------------------------------------------------------*
  159.     move.l        numtext_ptr,a1
  160.     moveq        #-1,d0
  161. .lp    addq.l        #1,d0
  162.     tst.b        (a0)+
  163.     bne.s        .lp
  164.     subq.l        #1,a0
  165.     bra.s        .go
  166. .cop:    move.b        -(a0),-(a1)
  167. .go:    dbra        d0,.cop
  168.     move.l        a1,numtext_ptr
  169.     rts
  170.  
  171. *-------------------------------------------------------*
  172. *    Print single character                *
  173. *-------------------------------------------------------*
  174. *    d0        character            *
  175. *    a1        screen                *            
  176. *-------------------------------------------------------*
  177.     txtlong
  178. *-------------------------------------------------------*
  179. print_char:
  180. *-------------------------------------------------------*
  181.     move.w        char_y,d7
  182.     move.l        a1,a3
  183.     mulu        scrwidth,d7
  184.     add.l        d7,d7
  185.     add.l        d7,a3
  186.     move.w        char_x,d7
  187.     ext.l        d7
  188.     add.l        d7,d7
  189.     add.l        d7,a3
  190.     lea        (a6,d0.w),a2
  191.     move.w        char_col,d1
  192.     move.w        #256,d6
  193.     move.w        scrwidth,d7
  194.     ext.l        d6
  195.     ext.l        d7
  196.     add.l        d7,d7
  197.     moveq        #6-1,d4
  198.     moveq        #0,d3
  199. .ylp    move.l        a3,a5
  200.     move.b        (a2),d0
  201.     add.b        d0,d0
  202.     bcc.s        .n1
  203.     move.w        d1,(a5)
  204. .n1    addq.l        #2,a5
  205.     add.b        d0,d0
  206.     bcc.s        .n2
  207.     move.w        d1,(a5)
  208. .n2    addq.l        #2,a5
  209.     add.b        d0,d0
  210.     bcc.s        .n3
  211.     move.w        d1,(a5)
  212. .n3    addq.l        #2,a5
  213.     add.b        d0,d0
  214.     bcc.s        .n4
  215.     move.w        d1,(a5)
  216. .n4    addq.l        #2,a5
  217.     add.b        d0,d0
  218.     bcc.s        .n5
  219.     move.w        d1,(a5)
  220. .n5    addq.l        #2,a5
  221.     add.b        d0,d0
  222.     bcc.s        .n6
  223.     move.w        d1,(a5)
  224. .n6    addq.l        #2,a5
  225.     tst.b        d3
  226.     beq.s        .next
  227.     add.b        d0,d0
  228.     bcc.s        .n7
  229.     move.w        d1,(a5)
  230. .n7    addq.l        #2,a5
  231.     add.b        d0,d0
  232.     bcc.s        .next
  233.     move.w        d1,(a5)
  234. .next    add.l        d6,a2
  235.     add.l        d7,a3
  236.     dbra        d4,.ylp
  237.     rts
  238.  
  239. *-------------------------------------------------------*
  240.     txtlong
  241. *-------------------------------------------------------*
  242. print_line:
  243. *-------------------------------------------------------*
  244.     pushall
  245.     move.l        fontptr,a6
  246.     move.l        screen,a1
  247. .loop    moveq        #0,d0
  248.     move.b        (a0)+,d0
  249.     beq.s        .out
  250.     cmp.w        #27,d0
  251.     beq.s        .ctrl
  252.     bsr        print_char
  253.     move.w        textgap,d0
  254.     add.w        d0,char_x
  255.     bra.s        .loop
  256. .out    popall
  257.     rts
  258. .ctrl    move.b        (a0)+,d0
  259.     cmp.b        #"Y",d0
  260.     beq.s        .pos
  261.     bra.s        .loop
  262. .pos    moveq        #0,d0
  263.     move.b        (a0)+,d0
  264.     move.w        d0,char_x
  265.     moveq        #0,d0
  266.     move.b        (a0)+,d0
  267.     add.w        d0,char_x
  268.     moveq        #0,d0
  269.     move.b        (a0)+,d0
  270.     move.w        d0,char_y
  271.     bra.s        .loop
  272.  
  273. *-------------------------------------------------------*
  274. init_font:
  275. *-------------------------------------------------------*
  276.     move.w        #6,textgap
  277.     move.l        #font,fontptr
  278.     move.l        fontptr,a0
  279.     lea        truefont,a1
  280.     move.w        #256-1,d0
  281. .char:    move.b        (a0)+,(a1)
  282.     move.b        (a0)+,256*1(a1)
  283.     move.b        (a0)+,256*2(a1)
  284.     move.b        (a0)+,256*3(a1)
  285.     move.b        (a0)+,256*4(a1)
  286.     move.b        (a0)+,256*5(a1)
  287.     addq.l        #1,a1
  288.     dbra        d0,.char
  289.     lea        truefont,a0
  290.     move.l        fontptr,a1
  291.     move.w        #256-1,d0
  292. .copy    move.l        (a0)+,(a1)+
  293.     move.w        (a0)+,(a1)+
  294.     dbra        d0,.copy
  295.     rts
  296.  
  297. *-------------------------------------------------------*
  298.     txtlong
  299. *-------------------------------------------------------*
  300. framecounter:
  301. *-------------------------------------------------------*
  302.     addq.l        #1,fpsc
  303.     ifd        debuggable
  304.     jmp        ([old_timerc.l])
  305.     elseif
  306.     bclr        #5,$FFFFFA11.w
  307.     rte
  308.     endc
  309.  
  310. *-------------------------------------------------------*
  311.     txtlong
  312. *-------------------------------------------------------*
  313. new_vbi:
  314. *-------------------------------------------------------*
  315.     tst.w        timer
  316.     beq.s        .nd
  317.     subq.w        #1,timer
  318. .nd:    addq.l        #1,vbls
  319.     addq.w        #1,frame
  320.     ifd        debuggable
  321.     rts
  322.     elseif
  323.     rte
  324.     endc
  325.  
  326. *-------------------------------------------------------*
  327.             datlong
  328. *-------------------------------------------------------*
  329.     
  330. fps:            dc.b    " FPS",0
  331. frames:            dc.b    " VBL",0
  332. point:            dc.b    ".",0
  333.  
  334. *-------------------------------------------------------*
  335.             bsslong
  336. *-------------------------------------------------------*
  337.  
  338. old_vbi:        ds.l    1
  339. old_timerc:        ds.l    1
  340. numtext_ptr:        ds.l    1
  341. fontptr:        ds.l    1
  342.  
  343. vbls:            ds.l    1
  344. ovbls:            ds.l    1
  345. fpsc:            ds.l    1
  346. fpso:            ds.l    1
  347. fc_history:        ds.l    8
  348.  
  349. timer:            ds.w    1
  350. char_x:            ds.w    1
  351. char_y:            ds.w    1
  352. char_col:        ds.w    1
  353. textgap:        ds.w    1
  354.  
  355. truefont:        ds.w    256*8*8
  356.  
  357.             ds.b    256
  358. stringspace:        ds.b    1
  359.  
  360. *-------------------------------------------------------*
  361.             txtlong
  362. *-------------------------------------------------------*
  363.